package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.impl.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author milian
 * @Date 2021/11/11 0011 16:19
 */
@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private HotelService hotelService;

    @PostMapping("/list")
    public ResponseEntity hotelList(@RequestBody RequestParams params){
        PageResult pageResult = hotelService.search(params);
        return ResponseEntity.ok(pageResult);
    }

    @PostMapping("/filters")
    public ResponseEntity filtersList(@RequestBody RequestParams params){
        Map<String, List<String>> map = hotelService.filtersList(params);
        return ResponseEntity.ok(map);

    }
    @GetMapping("suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return hotelService.getSuggestions(prefix);
    }
}
